package com.mcflies.ui.aidl_service;

import com.mcflies.commons.McfliesConstant;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

/**
 * @author:mcfly_jun
 * @create_date:2012-8-12
 * @comment:08-12 12:21:01.638: DEBUG/SntpClient(59): request time failed:
 *                java.net.SocketException: Address family not supported by
 *                protocol
 */
public class AIDLAndServiceMusicService extends Service {
	private static MediaPlayer mediaPlayer;

	private IServicePlayer.Stub stub = new IServicePlayer.Stub() {

		@Override
		public void stop() throws RemoteException {
			mediaPlayer.stop();
		}

		@Override
		public boolean setLoop(boolean loop) throws RemoteException {
			return false;
		}

		@Override
		public void seekTo(int current) throws RemoteException {
			mediaPlayer.seekTo(current);
		}

		@Override
		public void play() throws RemoteException {
			mediaPlayer.start();
		}

		@Override
		public void pause() throws RemoteException {
			mediaPlayer.pause();
		}

		@Override
		public int getDuration() throws RemoteException {
			return mediaPlayer.getDuration();
		}

		@Override
		public int getCurrentPosition() throws RemoteException {
			return mediaPlayer.getCurrentPosition();
		}
	};

	@Override
	public IBinder onBind(Intent intent) {
		return stub;
	}

	@Override
	public void onCreate() {
		Log.i(McfliesConstant.MCFLIES_LOGINFO_FLAG,
				"AIDLAndServiceMusicService-->onCreate");
		mediaPlayer = MediaPlayer.create(getApplicationContext(),
				AIDLAndServicePlayUtil.getFileinSD("K 歌之王.mp3"));
	}
}
